#include "msg_queue.h"

int write_msg_queue(char *data){
		struct mymsgbuf buf;	
		int msgid;
		if((msgid = msgget(0x1234, 0666|IPC_CREAT)) < 0)	
		{
			fprintf(stderr, "open msg %x failed.\n", 0x1234);
			return;
		}
		while(strncmp(buf.ctext, "exit", 4))	
		{
			memset(&buf, 0, sizeof(buf));
			fgets(buf.ctext, sizeof(buf.ctext), stdin);//从缓冲区读取内容
			buf.mtype = getpid();

			while((msgsnd(msgid, &buf, strlen(buf.ctext),0)) < 0)//发送信息到消息队列中
			{
				if(errno == EINTR)
					continue;
				return;		
			}

		}
		return 0;
}
